import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.*;

public class meanVote {
	
public static void main(String[] args) {
		
		try {
			
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String filename = "C:/zeus.mdb";
            String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
            database+= filename.trim() + ";DriverID=22;READONLY=true}";
            Connection con = DriverManager.getConnection(database ,"","");
            
            
            Statement stmt = con.createStatement();
            ResultSet rs;
            
            int userID = 10001;
            while(userID <= 42711){
       
            	rs = stmt.executeQuery("SELECT * FROM casebase WHERE UserID = "+userID);
            
            	int sumVotes = 0;
            	int count = 0;
            
            	while ( rs.next() ) {
            		sumVotes += rs.getInt("Votes");
            		count++;
            	}
            	float meanvote = (float)sumVotes/(float)count;
            	Statement insertStmt = con.createStatement();
            	insertStmt.execute("insert into meanvotes values("+userID+","+meanvote+")");
            	userID++;
            }
            con.close();
			
			
		}catch(Exception e){
			e.printStackTrace();
		}

 	}
}